DeadList = [];
WorldCenter = getArray(configFile>>"CfgWorlds">>worldName>>"centerPosition");

if (isNil "paramsArray") then {
	if (isClass (missionConfigFile/"Params")) then {
		diag_log Format["ParamClass (%1): %2",isNil "paramsArray", count (missionConfigFile/"Params")];
		for "_i" from 0 to (count (missionConfigFile/"Params") - 1) do {
			_paramName = configName ((missionConfigFile >> "Params") select _i);
			missionNamespace setVariable [_paramName, getNumber (missionConfigFile >> "Params" >> _paramName >> "default")];
			diag_log Format["Param %1: %2",_paramName, (missionNameSpace getVariable _paramName)];
		};
	};
} else {
	diag_log Format["ParamArray (%1): %2",isNil "paramsArray",count paramsArray];
	for "_i" from 0 to (count paramsArray - 1) do {
		missionNamespace setVariable [configName ((missionConfigFile >> "Params") select _i), paramsArray select _i];
		diag_log Format["Param %1: %2",(configName ((missionConfigFile >> "Params") select _i)), (paramsArray select _i)];
	};
};

_i = 0;
_not_found_obj = 0;
_task_marker = "";
_local_task_marker = "";
while {_not_found_obj < 100} do {
	_k = 0;
	_not_found = 0;
	_none_found = true;
	while {_not_found < 10} do {
		_task_marker = format["marker%1_%2",_i, _k];
		_local_task_marker = format["local_marker%1_%2",_i,_k];
		if (((getMarkerPos _task_marker) distance [0,0,0]) > 0) then {
			_text_marker = markerText _task_marker;
			createMarkerLocal [_local_task_marker, (getMarkerPos _task_marker)];
			_local_task_marker setMarkerTextLocal (_text_marker call XfTranslate);
			_local_task_marker setMarkerSizeLocal (markersize _task_marker);
			_local_task_marker setMarkerTypeLocal (markertype _task_marker);
			_local_task_marker setMarkerColorLocal (markercolor _task_marker);
			_local_task_marker setMarkerShapeLocal (markershape _task_marker);
			_local_task_marker setMarkerBrushLocal (markerbrush _task_marker);
			_local_task_marker setMarkerDirLocal (markerdir _task_marker);
			_task_marker setMarkerAlpha 0;
			if (_i > 0) then { _local_task_marker setMarkerAlphaLocal 0; };
			_none_found = false;
		} else {
			_not_found = _not_found + 1;
		};
		_k = _k + 1;
	};
	if (_none_found) then {
		_not_found_obj = _not_found_obj + 1;
	};
	_i = _i + 1;
};

// Hide random infantry and random motorized spawn markers
_not_found = 0;
_index = 0;
while { _not_found < 5 } do {
	_name = format["inf_%1",_index];
	if (((getMarkerPos _name) distance [0,0,0]) > 0) then {
		_name setMarkerAlpha 0;
	} else {
		_not_found = _not_found + 1;
	};
	_index = _index + 1;
};
_not_found = 0;
_index = 0;
while { _not_found < 5 } do {
	_name = format["mech_%1",_index];
	if (((getMarkerPos _name) distance [0,0,0]) > 0) then {
		_name setMarkerAlpha 0;
	} else {
		_not_found = _not_found + 1;
	};
	_index = _index + 1;
};

BOX_COUNT = 0;
_box_idx = 0;
_not_found = 0;
while {_not_found < 10} do {
	_box_marker = format["box_%1",_box_idx];
	_box_idx = _box_idx + 1;
	_box_pos = getMarkerPos _box_marker;
	if ((_box_pos distance [0,0,0]) < 1) then { _not_found = _not_found + 1; };
};
BOX_COUNT = _box_idx;

CONFIG_Default_ViewDistance = 5;
CONFIG_Default_Grass = 0;

_side_players = d_own_side;
_side_unit = "";
_sides = [];
if (X_MP) then {
	{
		_side_unit = str (side _x);
		if ((_sides find _side_unit) < 0) then {
			_sides set[count _sides, _side_unit];
		};
	} foreach playableUnits;
	if (count _sides == 1) then {
		_side_players = _sides select 0;
	};
} else {
	_side_players = str (side player);
};
d_own_side = _side_players;

d_own_side = switch(toupper(d_own_side)) do {
			case "WEST":{"WEST"};
			case "EAST":{"EAST"};
			case "GUER":{"GUER"};
			case "RESISTANCE":{"GUER"};
			default{"WEST"};
};
d_side_own = switch(d_own_side) do {
			case "WEST":{west};
			case "EAST":{east};
			case "GUER":{resistance};
			default { west };
};
diag_log Format["Players Side: %1", d_own_side];

d_enemy_side = switch(toupper(d_own_side)) do {
			case "WEST":{
				if ((west getFriend east) < 0.6) then {
					"EAST"
				} else {
					"GUER"
				};
			};
			case "EAST":{
				if ((east getFriend west) < 0.6) then {
					"WEST"
				} else {
					"GUER"
				};
			};
			case "GUER":{
				if ((resistance getFriend west) < 0.6) then {
					"WEST"
				} else {
					"EAST"
				};
			};
			default{"EAST"};
};
d_side_enemy = switch(d_enemy_side) do {
			case "WEST":{west};
			case "EAST":{east};
			case "GUER":{resistance};
			default { east };
};
diag_log Format["Enemy Side: %1", d_enemy_side];


d_player_can_rescue = true;
	
// COMMON EVENTS
[0, "setweather", {_delay = _this select 0; _delay setRain (_this select 1); _delay setOvercast (_this select 2);}] call XNetAddEvent;
[0, "d_all_exec", {diag_log format["[%1] %2","d_all_exec",_this]; _this spawn compile (_this select 0)}] call XNetAddEvent;
// registers a new mission object on all systems
[0, "d_all_mobject", {waituntil{!(isNil "d_mission_functions_compiled")};_this call XfMissionRegisterObject;}] call XNetAddEvent;
// create/update/delete a mission marker on all systems
[0, "d_all_mmarker", {_this call XfMissionUpdateMarker;}] call XNetAddEvent;
// Executes an action triggered by a mission object on all systems
[0, "d_all_maction", {_this call XfMissionExecuteObjectAction;}] call XNetAddEvent;
// Creates/Updates a mission task on all systems
[0, "d_all_mtask", {[_this,false] call XfMissionUpdateTask;}] call XNetAddEvent;
// Cleans all mission elements
[0, "d_all_mclean", {_this call XfMissionCleanEvent;}] call XNetAddEvent;
// Delete ruins in the area
[0, "d_del_ruin", {_ruin = nearestObject [_this, "Ruins"];if (!isNull _ruin) then {deleteVehicle _ruin}}] call XNetAddEvent;
// Executes a mission function on all systems.
[0, "d_all_mexecute", {_fnct = _this select 0; _params = _this select 1; call compile Format["%1 spawn %2",_params, _fnct];}] call XNetAddEvent; // different handling
// Switches move for all players
[0, "d_nswm", {(_this select 0) switchmove (_this select 1)}] call XNetAddEvent;
// Set a global variable local to the computer
[0, "d_all_var", {missionNameSpace setVariable [_this select 0, _this select 1];}] call XNetAddEvent;

diag_log "i_common.sqf";